{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}

<div class="p-page">
	<form class="layui-form gg-form-bar border-t border-x" lay-filter="barsearchform">
		<div class="layui-input-inline" style="width:100px;">
			<select name="status">
				<option value="">项目状态</option>
				<option value="1">未开始</option>
				<option value="2">进行中</option>
				<option value="3">已完成</option>
				<option value="4">已关闭</option>
			</select>
		</div>
		<div class="layui-input-inline" style="width:160px;">
			<input type="text" name="director" placeholder="项目负责人，可多选" readonly class="layui-input picker-admin" data-type="2" autocomplete="off" />
			<input name="director_uid" style="display: none;" value="" />
		</div>
		<div class="layui-input-inline" style="width:300px">
			<input type="text" name="keywords" placeholder="关键字,项目名称/项目描述" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline" style="width:150px">
			<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="table-search"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
			<button type="reset" class="layui-btn layui-btn-reset" lay-filter="table-reset">清空</button>
		</div>
	</form>
	<table class="layui-hide" id="table_project" lay-filter="table_project"></table>
</div>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm tool-add" type="button" data-href="/project/index/add">+ 添加项目</button>
  </div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const auth = {$auth};
	const moduleInit = ['tool','tablePlus','oaPicker'];
	function gouguInit() {
		var table = layui.tablePlus, tool = layui.tool;
		
		layui.pageTable = table.render({
			elem: "#table_project"
			, toolbar: "#toolbarDemo"
			,url: "/project/index/datalist"
			,page: true
			,limit: 20
			,cellMinWidth: 80
			,height: 'full-112'
			,cols: [[
				{field:'id',width:80, title: 'ID号', align:'center'}
				,{ field: 'status', title: '项目状态', align: 'center', width: 90, templet: function (d) {
					var html = '<span class="check-status-color-' + d.status + '">『' + d.status_name + '』</span>';
					return html;
					}
				}
				,{field:'name',title: '项目名称',minWidth:240}
				,{field:'director_name',title: '负责人',width:80,align:'center'}
				,{ field:'range_time', title: '项目计划周期', align: 'center', width: 180}
				,{field:'step',title: '当前阶段及负责人',align: 'center',width: 180}
				,{field:'tasks_unfinish', align: 'center', style: 'color: #91CC75;', width: 90, 'title': '进行中任务' }
				,{field:'tasks_finish', align: 'center', style: 'color: #FAC858;', width: 90, 'title': '已完成任务' }
				,{field:'tasks_pensent', align: 'center', style: 'color: #EE6666;', width: 90, 'title': '任务完成率' }
				,{field:'admin_name',title: '创建人',width:80,align:'center'}
				,{field:'create_time', title: '创建时间',width:150,align:'center'}
				,{width:120,fixed:'right',title: '操作', align:'center',ignoreExport:true,templet: function(d){
					var html='';
					var btn1='<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">详细</a>';
					var btn2='<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
					var btn3='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
					if(auth == 1 || d.admin_id == login_admin || d.director_uid == login_admin){
						return '<div class="layui-btn-group">'+btn1+btn2+btn3+'</div>';
					}
					else{
						return btn1
					}
				}}
			]]
		});
			
		table.on('tool(table_project)',function (obj) {
			var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
			var data = obj.data;
			if (obj.event === 'view') {
				tool.side("/project/index/view?id="+data.id);
				return;
			}
			if (obj.event === 'edit') {
				tool.side("/project/index/add?id="+data.id);
				return;
			}
			if (obj.event === 'del') {
				layer.confirm('确定要删除该项目吗?', { icon: 3, title: '提示' }, function (index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/project/index/del", { id: data.id }, callback);
					layer.close(index);
				});
				return;
			}
		});
	}
</script>
{/block}
<!-- /脚本 -->